home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-03-19 | 6.0 KB | 99 lines | [TEXT/MMCC] |
- //------------------------------------------------------------------------------
- // File: menu.cp
- // Date: 7/18/94
- // Author: Bretton Wade
- //
- // Description: this file contains definitions related to menu handling
- //
- //------------------------------------------------------------------------------
-
- #include "event.h"
- #include "menu.h"
- #include "apple event.h"
- #include "window.h"
-
- //------------------------------------------------------------------------------
- // Handle Apple Menu About Event
- //------------------------------------------------------------------------------
- pascal OSErr HandleAboutItemEvent (AppleEvent*, AppleEvent*, long) // handle a menu selection of the about item
- { // begin
- Handle version = GetResource ('vers', 1); // get the version resource
- HLock (version); // lock the handle
- ParamText (pstr (&(*version)[6]), 0, 0, 0); // set up the parameter strings for the about box
- HUnlock (version); // unlock the handle
- ReleaseResource (version); // release the version resource
- Alert (256, NULL); // Open the alert that is the about box
- ResetAlrtStage (); // no more beeps...
- return noErr; // return with no error
- } // end
-
- //------------------------------------------------------------------------------
- // Handle all other apple menu events
- //------------------------------------------------------------------------------
- pascal OSErr HandleAppleMenuEvent (AppleEvent *AE, AppleEvent*, long) // generic routine for handling apple menu events
- { // begin
- AEDesc item; // data description
- if (AEGetAttributeDesc (AE, keyEventIDAttr, typeWildCard, &item) == noErr) // if the description is retrieved without an error
- { // begin
- Str255 DAName; // place to get the name of the selected item
- short itemNum = *(ulong *) *(item.dataHandle); // get the item number from the event
- MenuHandle myAppleMenu = GetMHandle (kAppleMenu); // get the menu handle
- GetItem (myAppleMenu, itemNum, DAName); // get the name of the item selected
- OpenDeskAcc (DAName); // open the item
- AEDisposeDesc (&item); // release the memory associated with the descriptor
- } // end
- return noErr; // return with no error
- } // end
-
- //------------------------------------------------------------------------------
- // Handle File Menu Quit Event
- //------------------------------------------------------------------------------
- pascal OSErr HandleQuitItemEvent (AppleEvent*, AppleEvent*, long) // handle a menu selection of the about item
- { // begin
- if (CloseAllWindows ()) // attempt to close all of the windows
- gFinished = TRUE; // say finished true
- return noErr; // return with no error
- } // end
-
- //------------------------------------------------------------------------------
- // Init Menus
- //------------------------------------------------------------------------------
- void InitAppMenus (void) // set up the menu bar
- { // begin
- Handle menuBar = GetNewMBar (128); // get the 'MBAR' resource
- SetMenuBar (menuBar); // use it
- DisposeHandle (menuBar); // get rid of the handle since we are done with it
- AddResMenu (GetMHandle (kAppleMenu), 'DRVR'); // add all the desk accesories and stuff to the apple menu
- DrawMenuBar (); // draw the new menu bar
- // apple menu item handlers
- AEInstallEventHandler (kAppleMenu, kAboutItemEvent, NewAEEventHandlerProc(HandleAboutItemEvent), 0, FALSE);
- AEInstallEventHandler (kAppleMenu, typeWildCard, NewAEEventHandlerProc(HandleAppleMenuEvent), 0, FALSE);
- // file menu item handlers
- AEInstallEventHandler (kFileMenu, kQuitItemEvent, NewAEEventHandlerProc(HandleQuitItemEvent), 0, FALSE);
- } // end
-
- //------------------------------------------------------------------------------
- // Handle Menu event
- //------------------------------------------------------------------------------
- bool HandleMenu (long code) // handle a menu event
- { // begin
- bool handled = FALSE; // flag to indicate whether or not the event was handled
- ulong menu = hiword (code); // the menu code
- if (menu) // if it is a valid menu
- { // begin
- SendToMyself (menu, loword (code)); // do the appropriately mapped menu action
- handled = TRUE; // set the handled flag to true
- } // end
- HiliteMenu (0); // turn off the menu hiliting
- return handled; // return whether or not the event was handled
- } // end
-
- //------------------------------------------------------------------------------
- // Adjust Menus
- //------------------------------------------------------------------------------
- void AdjustMenus (void) // adjust the menus for processing
- { // begin
- } // end
- //------------------------------------------------------------------------------
-
-